import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useCounterStore = defineStore('counter', () => {
  // 定义 state
  const count = ref(0)
  const name = ref('张三')
  // 定义 getters
  const double = computed(() => count.value * 2)

  // 定义 actions
  const increment = () => {
    count.value++
  } 

  const decrement = () => {
    count.value--
  }

  const setName = (val: string) => {
    name.value = val
  }
  // 千万不要忘记这里要 return
  return { count, double, increment, decrement, setName ,name}
}, {
  //方式1
  // unistorage: true // 开启后对 state 的数据读写都将持久化
  //方式2  指定持久化数据
  unistorage:{
    key:'name', //可选 非必填
    paths:['name']
  }
})